/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Component;

import GameObject.Sprite;
import java.awt.Rectangle;
import java.awt.event.MouseEvent;
import java.awt.image.BufferedImage;

/**
 *
 * @author Alvis
 */
public class MyCheckBox extends MyControlItem {

	protected boolean isChecked;

	protected MyCheckBox() {
	}

	public MyCheckBox(BufferedImage img, int x, int y) {
		isChecked = false;
		isForcus = false;
		isMousePressed = false;

		sprite = new Sprite(img, 1, 4, x, y);
	}

	public boolean isChecked() {
		return isChecked;
	}

	public void setChecked(boolean c) {
		isChecked = c;
		if (isChecked == true) {
			((Sprite)sprite).setFrame(3);
		} else {
			((Sprite)sprite).setFrame(1);
		}
	}

	public Rectangle getBound() {
		return sprite.getBound();
	}

	@Override
	public boolean mouseMoved(MouseEvent e) {
		if (!super.mouseMoved(e)) {
			if (isChecked == true) {
				((Sprite)sprite).setFrame(2);
			} else {
				((Sprite)sprite).setFrame(0);
			}
			return false;
		}
		if (isChecked == true) {
			((Sprite)sprite).setFrame(3);
		} else {
			((Sprite)sprite).setFrame(1);
		}
		return true;
	}

	@Override
	public boolean mouseReleased(MouseEvent e) {
		if (!super.mouseReleased(e)) {
			return false;
		}
		setChecked(!isChecked);
		return true;
	}
}
